package com.alpha.eceasy.mall.controller;

import com.alpha.eceasy.mall.api.entity.MallCommodityCategoryAsso;
import com.alpha.eceasy.core.R;
import com.alpha.eceasy.mall.api.vo.MallCommoditySpecificationVO;
import com.alpha.eceasy.mall.service.MallCommodityCategoryAssoService;
import com.alpha.eceasy.mall.service.impl.MallCommodityCategoryAssoServiceImpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 商品与品类关系表
 *
 * @author huangpengfei
 * @since 2022-02-11 16:55:59
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/commodity-category-asso")
@Tag(description = "commodity-category-asso", name = "商品与品类关系表")
public class MallCommodityCategoryAssoController {

    private final MallCommodityCategoryAssoServiceImpl mallCommodityCategoryAssoService;

    /**
     * 分页查询
     *
     * @param mallCommodityCategoryAsso 商品与品类关系表
     */
    @Operation(description = "分页查询", summary = "分页查询")
    @GetMapping("")
    public R<IPage<MallCommoditySpecificationVO>> getMallCommoditySpecificationVOPage(@RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNumber,
                                                                                     @RequestParam(value = "pageSize", required = false, defaultValue = "10000") Integer pageSize,
                                                                                     MallCommodityCategoryAsso mallCommodityCategoryAsso) {
        return R.ok(mallCommodityCategoryAssoService.getMallCommoditySpecificationVOPage(Page.of(pageNumber, pageSize), mallCommodityCategoryAsso));
    }

    /**
     * 通过id查询商品与品类关系表
     *
     * @param id id
     * @return R 返回结果
     */
    @Operation(description = "通过id查询", summary = "通过id查询")
    @GetMapping("/{id}")
    public R<MallCommodityCategoryAsso> getById(@PathVariable("id") Long id) {
        return R.ok(mallCommodityCategoryAssoService.getById(id));
    }

    /**
     * 新增商品与品类关系表
     *
     * @param mallCommodityCategoryAsso 商品与品类关系表
     * @return R 返回结果
     */
    @Operation(description = "新增商品与品类关系表", summary = "新增商品与品类关系表")
    //@SysLog("新增商品与品类关系表")
    @PostMapping
    public R<Boolean> save(@RequestBody MallCommodityCategoryAsso mallCommodityCategoryAsso) {
        return R.ok(mallCommodityCategoryAssoService.save(mallCommodityCategoryAsso));
    }

    /**
     * 修改商品与品类关系表
     *
     * @param mallCommodityCategoryAsso 商品与品类关系表
     * @return R 返回结果
     */
    @Operation(description = "修改商品与品类关系表", summary = "修改商品与品类关系表")
    //@SysLog("修改商品与品类关系表")
    @PutMapping
    public R<Boolean> updateById(@RequestBody MallCommodityCategoryAsso mallCommodityCategoryAsso) {
        return R.ok(mallCommodityCategoryAssoService.updateById(mallCommodityCategoryAsso));
    }
}
